#include "editbox.h"


bool editbox::DrawEditBox (hgeSprite * spr)
{
  spr->Render(this->xPosition,this->yPosition);
	return true;
}

editbox::editbox(int xPos,int yPos)
{ 
 xPosition=xPos;
 yPosition=yPos;
 caretCurrentPosition=0;
 text_to_draw[0]='\0';
 text[0]='\0';
 //memset(text_to_draw,' ',64);
 //memset(text,' ',64);
}


void editbox::DrawTextIntoMenu(hgeFont * font,int xPosition,int yPosition)
{
    //font->SetColor(color);
	font->Render(xPosition,yPosition,HGETEXT_LEFT,text_to_draw);
}

void editbox::SetTextIntoMenu(int _text,int key)
{
  if(key==HGEK_BACKSPACE)
  {
	  caretCurrentPosition--;
	  text[caretCurrentPosition]='\0';
	  strncpy(text_to_draw,text,caretCurrentPosition+1);
  }
  else 
	  if (key>2)
      {
       text[caretCurrentPosition]=_text;
       text[caretCurrentPosition+1]='\0';
       caretCurrentPosition++;
       strncpy(text_to_draw,text,caretCurrentPosition+1);
      }
 }

void editbox::clearEditForm()
{
 text_to_draw[0]='\0';
 text[0]='\0';
 caretCurrentPosition=0;
}